<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="任课教师" prop="tName">
        <el-input
          v-model="queryParams.tName"
          placeholder="请输入任课教师姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="巡视人" prop="supName">
        <el-input
          v-model="queryParams.supName"
          placeholder="请输入巡视人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['patrol:dailyInspectionOutclass:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['patrol:dailyInspectionOutclass:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['patrol:dailyInspectionOutclass:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['patrol:dailyInspectionOutclass:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dailyInspectionOutclassList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="巡查表号" align="center" prop="dailyInspectionId" />
      <el-table-column label="课程名称" align="center" prop="courseName" />
      <el-table-column label="任课教师" align="center" prop="tName" />
      <el-table-column label="年级专业班级" align="center" prop="teachClass" />
      <el-table-column label="巡视人" align="center" prop="supName" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="openTableModal(scope.$index)"
          >查看详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['patrol:dailyInspectionOutclass:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['patrol:dailyInspectionOutclass:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改提前下课记录 对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="550px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="巡查表号" prop="dailyInspectionId">
          <el-input v-model="form.dailyInspectionId" disabled />
        </el-form-item>
        <el-form-item label="巡视人" prop="supName">
          <el-input v-model="form.supName" disabled />
        </el-form-item>
        <el-form-item label="上课教室" prop="classroom">
          <el-input v-model="form.classroom" placeholder="请输入上课教室" clearable />
        </el-form-item>
        <el-form-item label="正常下课时间" prop="normalTime">
          <el-date-picker clearable size="small"
            v-model="form.normalTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择正常下课时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="实际下课时间" prop="actualTime">
          <el-date-picker clearable size="small"
            v-model="form.actualTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择实际下课时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="课程名称" prop="courseName">
          <el-input v-model="form.courseName" placeholder="请输入课程名称" clearable />
        </el-form-item>
        <el-form-item label="任课教师" prop="tName">
          <el-input v-model="form.tName" placeholder="请输入任课教师" clearable />
        </el-form-item>
        <el-form-item label="年级专业班级" prop="teachClass">
          <el-input v-model="form.teachClass" placeholder="请输入年级专业班级" clearable />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 查看日常巡查记录表Modal -->
    <el-dialog :title="title" :visible.sync="openTable" width="800px" append-to-body>
      <el-descriptions class="margin-top" :model="outclassTable" title="教师提前下课情况记录表" :column="2" border>
        <template slot="extra">
          {{ "记录时间：" + outclassTable.createTime }}
        </template>

        <el-descriptions-item>
          <template slot="label">
            巡查人
          </template>
          {{outclassTable.supName }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            巡查表号
          </template>
          {{outclassTable.dailyInspectionId }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            上课教室
          </template>
          {{outclassTable.teachClass }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            正常下课时间
          </template>
          {{outclassTable.normalTime }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            实际下课时间
          </template>
          {{ outclassTable.actualTime }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            课程名称
          </template>
          {{outclassTable.courseName}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            任课教师
          </template>
          {{outclassTable.tName}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            年级专业班级
          </template>
          {{outclassTable.teachClass}}
        </el-descriptions-item>
      </el-descriptions>
    </el-dialog>
  </div>
</template>

<script>
import { listDailyInspectionOutclass, getDailyInspectionOutclass, delDailyInspectionOutclass, addDailyInspectionOutclass, updateDailyInspectionOutclass } from "@/api/patrol/dailyInspectionOutclass";

export default {
  name: "DailyInspectionOutclass",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 提前下课记录 表格数据
      dailyInspectionOutclassList: [],
      outclassTable: {},
      openTable: false,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dailyInspectionId: null,
      supName: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dailyInspectionId: null,
        tName: null,
        supName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        classroom: [
          { required: true, message: "上课教室不能为空", trigger: "blur" }
        ],
        normalTime: [
          { required: true, message: "正常下课时间不能为空", trigger: "blur" }
        ],
        actualTime: [
          { required: true, message: "实际下课时间不能为空", trigger: "blur" }
        ],
        courseName: [
          { required: true, message: "课程名称不能为空", trigger: "blur" }
        ],
        tName: [
          { required: true, message: "任课教师不能为空", trigger: "blur" }
        ],
        teachClass: [
          { required: true, message: "年级专业班级不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    const dailyInspectionId = this.$route.query && this.$route.query.dailyInspectionId;
    const supName = this.$route.query && this.$route.query.supName;
    this.dailyInspectionId = dailyInspectionId
    this.supName = supName
    this.getList();
  },
  methods: {
    /** 查询提前下课记录 列表 */
    getList() {
      this.loading = true;
      this.queryParams.dailyInspectionId = this.dailyInspectionId
      listDailyInspectionOutclass(this.queryParams).then(response => {
        this.dailyInspectionOutclassList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dailyInspectionId: this.dailyInspectionId,
        classroom: null,
        normalTime: null,
        actualTime: null,
        courseName: null,
        tName: null,
        teachClass: null,
        supName: this.supName,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      const dailyInspectionId = this.dailyInspectionId
      const supName = this.supName
      if (dailyInspectionId != null && supName != null) {
        this.reset();
        this.open = true;
        this.title = "添加提前下课记录 ";
      } else {
        this.$modal.msgError("请从日常巡查表中添加！");
      }
      
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDailyInspectionOutclass(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改提前下课记录 ";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDailyInspectionOutclass(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDailyInspectionOutclass(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      const dailyInspectionId = row.dailyInspectionId
      const supName = row.supName
      this.$modal.confirm('是否确认删除提前下课记录 编号为"' + ids + '"的数据项？').then(function() {
        return delDailyInspectionOutclass(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('patrol/dailyInspectionOutclass/export', {
        ...this.queryParams
      }, `dailyInspectionOutclass_${new Date().getTime()}.xlsx`)
    },
    /** 查看详情 */
    openTableModal(index) {
      const no = index
      this.outclassTable = this.dailyInspectionOutclassList[no]
      this.openTable = true;
      this.title = "查看教师提前下课情况记录表";
    }
  }
};
</script>
